FROM {{ namespace }}/{{ image_prefix }}base:{{ tag }}
LABEL maintainer="{{ maintainer }}" name="{{ image_name }}" build-date="{{ build_date }}"

{% block openstack_base_header %}{% endblock %}

{% import "macros.j2" as macros with context %}

{% if install_type == 'binary' %}
    {% if base_package_type == 'rpm' %}

        {% set openstack_base_packages = [
            'avahi-libs',
            'gnutls',
            'initscripts',
            'libxslt',
            'libyaml',
            'mailcap',
            'openssl',
            'systemd-sysv'
        ] %}
        {% if distro_python_version.startswith('3') %}
        {% set openstack_base_packages = openstack_base_packages + [
            'python3-PyYAML',
            'python3-alembic',
            'python3-anyjson',
            'python3-aodhclient',
            'python3-barbicanclient',
            'python3-cachetools',
            'python3-cloudkittyclient',
            'python3-congressclient',
            'python3-contextlib2',
            'python3-cryptography',
            'python3-designateclient',
            'python3-elasticsearch',
            'python3-eventlet',
            'python3-extras',
            'python3-glanceclient',
            'python3-gnocchiclient',
            'python3-heatclient',
            'python3-httplib2',
            'python3-ironicclient',
            'python3-iso8601',
            'python3-kazoo',
            'python3-keystoneauth1',
            'python3-keystoneclient',
            'python3-keystonemiddleware',
            'python3-logutils',
            'python3-lxml',
            'python3-magnumclient',
            'python3-manilaclient',
            'python3-migrate',
            'python3-mimeparse',
            'python3-mistralclient',
            'python3-muranoclient',
            'python3-neutronclient',
            'python3-novaclient',
            'python3-openstackclient',
            'python3-oslo-cache',
            'python3-oslo-concurrency',
            'python3-oslo-config',
            'python3-oslo-context',
            'python3-oslo-db',
            'python3-oslo-i18n',
            'python3-oslo-log',
            'python3-oslo-messaging',
            'python3-oslo-middleware',
            'python3-oslo-policy',
            'python3-oslo-reports',
            'python3-oslo-rootwrap',
            'python3-oslo-serialization',
            'python3-oslo-service',
            'python3-oslo-upgradecheck',
            'python3-oslo-utils',
            'python3-oslo-versionedobjects',
            'python3-osprofiler',
            'python3-paramiko',
            'python3-paste-deploy',
            'python3-pbr',
            'python3-pika',
            'python3-posix_ipc',
            'python3-prettytable',
            'python3-psycopg2',
            'python3-pyasn1',
            'python3-redis',
            'python3-retrying',
            'python3-routes',
            'python3-saharaclient',
            'python3-sqlalchemy',
            'python3-sqlalchemy-collectd',
            'python3-sqlparse',
            'python3-swiftclient',
            'python3-sysv_ipc',
            'python3-tooz',
            'python3-troveclient',
            'python3-vitrageclient',
            'python3-webob',
            'python3-zaqarclient',
        ] %}
        {% else %}
        {% set openstack_base_packages = openstack_base_packages + [
            'python2-cryptography',
            'python2-eventlet',
            'python2-iso8601',
            'python2-oslo-cache',
            'python2-oslo-concurrency',
            'python2-oslo-config',
            'python2-oslo-context',
            'python2-oslo-db',
            'python2-oslo-i18n',
            'python2-oslo-log',
            'python2-oslo-messaging',
            'python2-oslo-middleware',
            'python2-oslo-policy',
            'python2-oslo-reports',
            'python2-oslo-rootwrap',
            'python2-oslo-serialization',
            'python2-oslo-service',
            'python2-oslo-upgradecheck',
            'python2-oslo-utils',
            'python2-oslo-versionedobjects',
            'python2-pika',
            'python2-pyasn1',
            'python2-sysv_ipc',
            'python2-alembic',
            'python-anyjson',
            'python-aodhclient',
            'python-barbicanclient',
            'python2-cachetools',
            'python-cloudkittyclient',
            'python-congressclient',
            'python-contextlib2',
            'python-designateclient',
            'python-elasticsearch',
            'python2-extras',
            'python-futures',
            'python-glanceclient',
            'python-gnocchiclient',
            'python-heatclient',
            'python-httplib2',
            'python-ironicclient',
            'python-kazoo',
            'python-keystoneauth1',
            'python-keystoneclient',
            'python-keystonemiddleware',
            'python-logutils',
            'python-lxml',
            'python-magnumclient',
            'python-manilaclient',
            'python-migrate',
            'python2-mimeparse',
            'python-mistralclient',
            'python-muranoclient',
            'python-neutronclient',
            'python-novaclient',
            'python-openstackclient',
            'python-osprofiler',
            'python-paramiko',
            'python-paste-deploy',
            'python-pbr',
            'python-posix_ipc',
            'python-prettytable',
            'python-psycopg2',
            'python-redis',
            'python-retrying',
            'python-routes',
            'python-saharaclient',
            'python2-sqlalchemy',
            'python2-sqlalchemy-collectd',
            'python-sqlparse',
            'python-swiftclient',
            'python-tooz',
            'python-troveclient',
            'python-vitrageclient',
            'python2-webob',
            'python-zaqarclient',
            'PyYAML',
            'sysvinit-tools'
        ] %}
        {% endif %}

    {% elif base_package_type == 'deb' %}

# This will prevent questions from being asked during the install
ENV DEBIAN_FRONTEND noninteractive
        {% set openstack_base_packages = [
            'openssl',
            'patch',
            'python3-aodhclient',
            'python3-barbicanclient',
            'python3-congressclient',
            'python3-designateclient',
            'python3-elasticsearch',
            'python3-etcd',
            'python3-etcd3gw',
            'python3-gnocchiclient',
            'python3-heatclient',
            'python3-ironicclient',
            'python3-kazoo',
            'python3-keystoneclient',
            'python3-magnumclient',
            'python3-manilaclient',
            'python3-memcache',
            'python3-mistralclient',
            'python3-muranoclient',
            'python3-mysqldb',
            'python3-openstackclient',
            'python3-oslo.log',
            'python3-osprofiler',
            'python3-pip',
            'python3-psycopg2',
            'python3-pymemcache',
            'python3-pymysql',
            'python3-pyngus',
            'python3-redis',
            'python3-saharaclient',
            'python3-sysv-ipc',
            'python3-swiftclient',
            'python3-troveclient',
            'python3-zake',
            'python3-zaqarclient'
        ] %}
    {% endif %}

{{ macros.install_packages(openstack_base_packages | customizable("packages")) }}

{% elif install_type == 'source' %}
    {% if base_package_type == 'rpm' %}
        {% set openstack_base_packages = [
            'gcc',
            'gcc-c++',
            'git',
            'iproute',
            'libffi-devel',
            'libxml2-devel',
            'libxslt-devel',
            'libyaml-devel',
            'mariadb-devel',
            'openldap-devel',
            'openssl',
            'openssl-devel',
            'postgresql',
            'postgresql-devel',
            'sqlite-devel',
            'zip'
        ] %}
        {% if distro_python_version.startswith('3') %}
            {% set openstack_base_packages = openstack_base_packages + [
                'python3-devel',
            ] %}
        {% else %}
            {% set openstack_base_packages = openstack_base_packages + [
                'python-devel',
            ] %}
        {% endif %}

    {% elif base_package_type == 'deb' %}
        {% set openstack_base_packages = [
            'build-essential',
            'ca-certificates',
            'git',
            'libffi-dev',
            'libmariadb-dev-compat',
            'libpq-dev',
            'libssl-dev',
            'libxml2-dev',
            'libxslt1-dev',
            'libyaml-dev',
            'libz-dev',
            'pkg-config',
            'python3-dev',
            'zip'
        ] %}

    {% endif %}

{{ macros.install_packages(openstack_base_packages | customizable("packages")) }}

{% block source_install_python_pip %}
{{ macros.get_pip() }}
{% endblock %}

{% set openstack_base_pip_packages = [
        'Babel',
        'Mako',
        'MarkupSafe',
        'Paste',
        'PasteDeploy',
        'PyNaCl',
        'PyYAML',
        'Routes',
        'SQLAlchemy',
        'Tempita',
        'WebOb',
        'WSME',
        'alembic',
        'amqp',
        'anyjson',
        'aodhclient',
        'appdirs',
        'bcrypt',
        'cachetools',
        'cliff',
        'cmd2',
        'cryptography',
        'contextlib2',
        'debtcollector',
        'decorator',
        'elasticsearch',
        'eventlet',
        'fasteners',
        'funcsigs',
        'futurist',
        'gnocchiclient',
        'greenlet',
        'iso8601',
        'jinja2',
        'jsonpatch',
        'jsonpointer',
        'jsonschema',
        'keystoneauth1',
        'keystonemiddleware',
        'kombu',
        'logutils',
        'monotonic',
        'mysqlclient',
        'netaddr',
        'netifaces',
        'os-client-config',
        'oslo.concurrency',
        'oslo.config',
        'oslo.context',
        'oslo.db',
        'oslo.i18n',
        'oslo.log',
        'oslo.messaging',
        'oslo.middleware',
        'oslo.policy',
        'oslo.serialization',
        'oslo.service',
        'oslo.utils',
        'oslo.vmware',
        'osprofiler',
        'pbr',
        'pecan',
        'pika',
        'prettytable',
        'psutil',
        'pycadf',
        'pyinotify',
        'pymongo',
        'pymysql',
        'pyngus',
        'pyparsing',
        'pyroute2',
        'python-barbicanclient',
        'python-cinderclient',
        'python-cloudkittyclient',
        'python-congressclient',
        'python-dateutil',
        'python-designateclient',
        'python-editor',
        'python-glanceclient',
        'python-heatclient',
        'python-ironicclient',
        'python-keystoneclient',
        'python-magnumclient',
        'python-manilaclient',
        'python-memcached',
        'python-mistralclient',
        'python-muranoclient',
        'python-neutronclient',
        'python-novaclient',
        'python-openstackclient',
        'python-qpid-proton',
        'python-saharaclient',
        'python-swiftclient',
        'python-troveclient',
        'python-vitrageclient',
        'python-zaqarclient',
        'pytz',
        'repoze.lru',
        'requests',
        'requestsexceptions',
        'retrying',
        'setproctitle',
        'simplegeneric',
        'simplejson',
        'six',
        'sqlalchemy-migrate',
        'sqlparse',
        'stevedore',
        'tooz[consul,etcd,etcd3,etcd3gw,zake,redis,postgresql,mysql,zookeeper,memcached,ipc]',
        'unicodecsv',
        'warlock',
        'wrapt'
    ]
%}

{% if distro_python_version == '2.7' %}
    {% set openstack_base_pip_packages = openstack_base_pip_packages + [
             'enum34',
             'functools32',
             'futures'
         ]
    %}
{% endif %}

ADD openstack-base-archive /openstack-base-source
RUN ln -s openstack-base-source/* /requirements \
    && mkdir -p /var/lib/kolla \
    && {{ macros.install_pip(['virtualenv'], constraints = false)}} \
    && virtualenv --system-site-packages /var/lib/kolla/venv

ENV PATH /var/lib/kolla/venv/bin:$PATH

RUN {{ macros.install_pip(openstack_base_pip_packages | customizable("pip_packages")) }}

{% endif %}

{% block openstack_base_footer %}{% endblock %}
